package com.i2bt.app.set.model;

import com.i2bt.common.AndroidRestContract;

import com.i2bt.app.BaseActivity;
import com.i2bt.app.BaseJsonModel;
import com.i2bt.app.set.BindHomeBoxActivity;
import com.i2bt.bean.BindHomeBoxBean;

import org.json.JSONException;
import org.json.JSONObject;

public class BindJsonHandle extends BaseJsonModel {
	BindHomeBoxActivity act;
	private String[][] homeHoxInfo;

	public BindJsonHandle(BaseActivity activity) {
		super(activity);
		// TODO Auto-generated constructor stub
		act = (BindHomeBoxActivity) this.activity;
	}

	@Override
	protected String logicToWrap() {
		// TODO Auto-generated method stub
		BindHomeBoxBean bean = (BindHomeBoxBean) this.beanParam;
		try {
			jsonParam.put(AndroidRestContract.ACTION, bean.getAct());
			jsonParam.put(AndroidRestContract.USER_ID, bean.getUserId());
			jsonParam.put(AndroidRestContract.PASSWORD, bean.getPassword());
			jsonParam.put(AndroidRestContract.HOMEBOX_NAME,
					bean.getHomeboxName());
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return jsonParam.toString();
	}

	@Override
	protected void logicToUnwrap(boolean isSuc, String result) {
		// TODO Auto-generated method stub
		System.out.println(result);
		if (isSuc) {
			try {
				JSONObject ja = new JSONObject(result);
				boolean succ = ja.getBoolean(AndroidRestContract.SUCCEED);
				String mes = null;
				if (succ) {
					mes = ja.getString(AndroidRestContract.HOMEBOX_ID);
					act.setIdentifyCode(mes);
				} else {
					mes = ja.getString(AndroidRestContract.MESSAGE);
					act.showWarnToast(mes);
				}
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} else {
			act.showWarnToast("网络连接失败");
		}
	}

	public String[][] getHomeHoxInfo() {
		return homeHoxInfo;
	}
}
